local skel = fk.CreateSkill {
  name = "lb__niyuan",
}

Fk:loadTranslationTable {
  ["lb__niyuan"] = "拟渊",
  [":lb__niyuan"] = "当一名角色使用虚拟或黑色伤害牌指定唯一目标时，若目标在你的攻击范围内，你可以重铸目标一张牌，然后目标角色不能使用或打出点数小于该重铸牌的手牌直到此牌结算完成。",

  ["@lb__niyuan-phase"] = "拟渊",
  ["#lb__niyuan"] = "拟渊：你可以重铸 %dest 一张牌，其不能使用或打出点数小于该重铸牌的手牌直到此牌结算完成",
  ["#lb__niyuan-cz"] = "拟渊：重铸 %dest 一张牌",

  ["$lb__niyuan1"] = "这份力量的沉重，你一无所知。",
  ["$lb__niyuan2"] = "生存还是毁灭，你别无选择。",
}

skel:addEffect(fk.TargetSpecifying, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and data:isOnlyTarget(data.to) and not data.to:isNude() and
        (data.to == player or player:inMyAttackRange(data.to))
        and ((data.card.is_damage_card and data.card.color == Card.Black) or data.card:isRuleVirtual())
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = skel.name,
      prompt = "#lb__niyuan::" .. data.to.id,
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local id = room:askToChooseCard(player, {
      target = data.to,
      flag = "he",
      skill_name = skel.name,
      prompt = "#lb__niyuan-cz::" .. data.to.id,
    })
    room:recastCard({ id }, data.to, skel.name)
    room:setPlayerMark(data.to, "@lb__niyuan-phase", Fk:getCardById(id).number)
    room.logic:getCurrentEvent():findParent(GameEvent.UseCard):addCleaner(function()
      for _, v in ipairs(room.players) do
        room:setPlayerMark(v, "@lb__niyuan-phase", 0)
      end
    end)
  end,
})

skel:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    return player:getMark("@lb__niyuan-phase") > 0 and card.number < player:getMark("@lb__niyuan-phase") and
        table.contains(player:getCardIds("h"), card.id)
  end,
  prohibit_response = function(self, player, card)
    return player:getMark("@lb__niyuan-phase") > 0 and card.number < player:getMark("@lb__niyuan-phase") and
        table.contains(player:getCardIds("h"), card.id)
  end,
})

return skel
